//Polymorphism should push_back pointer to container<Not reference!!!>
#include <iostream>
#include <vector>
using namespace std;

class Vehicle {
public:
  virtual void move(void) = 0;
  virtual ~Vehicle(){cout<<"~Vehicle()"<<endl;}
};

class Car: public Vehicle {
  void move(void) {cout<<"Car::move()"<<endl;}
  ~Car(){cout<<"~Car()"<<endl;}
};

class Rocket:public Vehicle {
  void move(void) {cout<<"Rocket::move()"<<endl;}
  ~Rocket(){cout<<"~Rocket()"<<endl;}
};

class Ufo: public Vehicle{
  void move(void) {cout<<"Ufo::move()"<<endl;}
  ~Ufo(){cout<<"~Ufo()"<<endl;}
};

int main(int argc, char *argv[]){
  vector<Vehicle*> v;
  vector<Vehicle*>::iterator iter;
  vector<Vehicle*>::reverse_iterator r_iter;
  
  Vehicle *v0 = new Car;
  Vehicle *v1 = new Rocket;
  Vehicle *v2 = new Ufo;
  v.push_back(v0);
  v.push_back(v1);
  v.push_back(v2);

  for(iter = v.begin();iter!=v.end();++iter){
    (*iter)->move();
  }

  for(r_iter = v.rbegin();r_iter!=v.rend();++r_iter) {
    delete (*r_iter);
  }
  
 
  return 0;
}
